#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#include "eic.h"
#include "CInet.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall CInternet::CInternet()
{
  m_hWininet                      = NULL;
  m_pfncInternetAutodial          = NULL;
  m_pfncInternetAutodialHangup    = NULL;
  m_pfncInternetGetConnectedState = NULL;

  m_ConnexionInterne              = false;

  if(( m_hWininet=::LoadLibrary( "wininet.dll"))!=NULL) {
    m_pfncInternetAutodial          = ( TInternetAutodial         )::GetProcAddress( m_hWininet, "InternetAutodial"         ); ASSERT( m_pfncInternetAutodial);
    m_pfncInternetAutodialHangup    = ( TInternetAutodialHangup   )::GetProcAddress( m_hWininet, "InternetAutodialHangup"   ); ASSERT( m_pfncInternetAutodialHangup);
    m_pfncInternetGetConnectedState = ( TInternetGetConnectedState)::GetProcAddress( m_hWininet, "InternetGetConnectedState"); ASSERT( m_pfncInternetGetConnectedState);
  }
}
//---------------------------------------------------------------------------
__fastcall CInternet::~CInternet()
{
  if( m_hWininet) ::FreeLibrary( m_hWininet);
}
//---------------------------------------------------------------------------
bool __fastcall CInternet::Connect(TCustomForm *pParentForm)
{
  if (IsConnected())
     return true;

  if( m_hWininet) {
     m_ConnexionInterne = m_pfncInternetAutodial( INTERNET_AUTODIAL_FORCE_ONLINE, pParentForm ? pParentForm->Handle : NULL);
  }

  return m_ConnexionInterne;
}
//---------------------------------------------------------------------------
void __fastcall CInternet::Disconnect()
{
  if(m_ConnexionInterne && m_hWininet)
     m_ConnexionInterne = !m_pfncInternetAutodialHangup(0);
}
//---------------------------------------------------------------------------
bool CInternet::IsConnected()
{
DWORD dwTemp;

if( m_pfncInternetGetConnectedState)
   return m_pfncInternetGetConnectedState(&dwTemp, 0);
else
   return false;
}

